import { ConfigService } from '@nestjs/config';
import * as mongoose from 'mongoose';

export const databaseProviders = [
  {
    provide: 'DATABASE_CONNECTION',
    inject: [ConfigService],
    useFactory: (config: ConfigService): Promise<typeof mongoose> => {
      const auth = config.get('db.auth');
      return mongoose.connect(config.get('db.uri'), {
        dbName: config.get('db.auth.dbName'),
        user: config.get('db.auth.user'),
        pass: config.get('db.auth.pass'),
        useFindAndModify: false,
      })
    },
  },
];
